package dongze.com.ckdj.adapter;

import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import java.util.List;

/**
 * Created by fanqwz on 2017/7/26.
 */

public class VehicleNumberAdapter extends BaseAdapter implements Filterable {
    final List<Pair<String, String>> data;

    public VehicleNumberAdapter(List<Pair<String, String>> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return data == null ? null : data.get(position).first;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
        }

        if (data.get(position).second == null || data.get(position).second.isEmpty()) {
            if (data.get(position).first != null && !data.get(position).first.isEmpty()) {
                ((TextView) convertView.findViewById(android.R.id.text1)).setText(data.get(position).first);
            } else {
                ((TextView) convertView.findViewById(android.R.id.text1)).setText("");
            }

        } else {
            ((TextView) convertView.findViewById(android.R.id.text1)).setText(data.get(position).first + "," + data.get(position).second);
        }

        return convertView;
    }

    @Override
    public Filter getFilter() {
        return filter;
    }

    Filter filter = new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            return null;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {

        }
    };
}